﻿using Pay.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Pay.DTO;
using Pay.TO;
using Pay.Token.Utils;
using System.Threading.Tasks;

namespace Pay.Token.Controllers {
    /// <summary>
    /// 创客商品
    /// </summary>
    [AppAuthorize("Member")]
    public class ProductTokenMakerController : GeneralController {
        private IProductService _iProductService;
        private IMerchantService _iMerchantService;
        private IAdvertisementService _iAdvertisementService;
        private IProductActivityService _iProductActivityService;

        public ProductTokenMakerController(IProductService iProductService, IMerchantService iMerchantService, IAdvertisementService iAdvertisementService, IProductActivityService iProductActivityService) {
            _iProductService = iProductService;
            _iMerchantService = iMerchantService;
            _iAdvertisementService = iAdvertisementService;
            _iProductActivityService = iProductActivityService;
        }

        [HttpGet, AllowAnonymous]
        public ActionResult Index() {
            var banner = _iAdvertisementService.AppGetAdvertisementList(new merch_advertisement_query_type() { position_type = 7, is_type = false });
            ViewBag.banner = banner;
            ViewBag.img_url = RequestMethod.token_imgurl;
            int userType = 3;
            if (UserId > 0) {
                var curUser = _iMerchantService.Get(UserId);
                userType = (int)curUser.usertype;
            }
            ViewBag.UserType = userType;
            ViewBag.UserId = UserId;
            return View();
        }

        [HttpPost, AllowAnonymous]
        public PartialViewResult _ProductList(GoodsQuery query) {
            ProductActivityQuery activityQuery = new ProductActivityQuery();
            activityQuery.ActivityType = EActivityType.ProductMaker;
            activityQuery.Time = DateTime.Now;
            activityQuery.page = query.page;
            activityQuery.size = query.size;
            activityQuery.sell_out = false;
            var merchant = _iMerchantService.Get(t_RequestMethod.merchant_no);
            activityQuery.merchant_id = merchant.id;
            var list = _iProductActivityService.Gets(activityQuery);
            //int userType = 3;
            //if(UserId > 0) {
            //    var curUser = _iMerchantService.Get(UserId);
            //    userType = (int)curUser.usertype;
            //}
            //ViewBag.UserType = userType;
            //ViewBag.UserId = UserId;
            return PartialView(list);
        }

        /// <summary>
        /// 创客商品详情（购买创客商品需要登录，做一次转发）
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Detail(long productId) {
            return Redirect("/DistributionMall/ProductDetail?productId=" + productId);
        }

    }
}